clear

import excel "Figure 4 Data.xlsx", sheet("Clean") firstrow

reshape long emp, i(id) j(date)

save "Table 4 Data.dta", replace

set more off
set matsize 800

gen month = date + 359
drop date
xtset id month, monthly

drop if month < 654 // July 2014

gen post = 0 // before and after dummies
replace post = 1 if month >= 727 // July 2020

gen treat_post = all_treat*post // beta3 interaction term

tabulate id, gen(id_dumm) // county dummies
tabulate month, gen(month_dumm) // month dummies

gen ln_emp = ln(emp)

sort id month

* county-specific time trends

bysort id: gen trend = _n

forval i = 1/77 {
	gen id_trend_dumm`i' = id_dumm`i'*trend
}

gen treat_trend = all_treat*trend

sort id month

* BORDER REGRESSIONS

* keep if border_treat == 1 | border_control == 1

* SECOND LAYER REGRESSIONS

* keep if layer_treat == 1 | layer_control == 1

* ALL COUNTIES

xtreg ln_emp all_treat post treat_post trend treat_trend, cluster(id)

xtreg ln_emp treat_post month_dumm* id_trend_dumm*, fe i(id) cluster(id)


